#include "playerapplication.h"
#include "LitePlayer.h"
#include "CSecureDataStore.h"
#include "Path.h"
#include "Account.h"


PlayerApplication::PlayerApplication(int &argc, char **argv):
    QApplication(argc, argv)
{
    av::LitePlayerFactory::startup();

	

	m_dataStore.reset(new CSecureDataStore());
	initData();
	
}

PlayerApplication::~PlayerApplication()
{
    av::LitePlayerFactory::cleanup();
}

std::shared_ptr< SecureDataStore > PlayerApplication::getSecureDataStore()
{
	return m_dataStore;
}

void PlayerApplication::initData()
{
	std::string appDir = applicationDirPath().toStdString();
	std::string filepath = comn::Path::join(appDir, "app.data");

	m_dataStore->open(filepath);

	if (!m_dataStore->contains(Account::ADMIN))
	{
		m_dataStore->setValue(Account::ADMIN, Account::ADMIN);
	}

	if (!m_dataStore->contains(Account::PROVIDER))
	{
		m_dataStore->setValue(Account::PROVIDER, Account::PROVIDER);
	}

    m_user = Account::ADMIN;
}

QString PlayerApplication::getUser()
{
    return m_user;
}

void PlayerApplication::setUser(const QString& user)
{
    m_user = user;
}

bool PlayerApplication::isSuperAdmin()
{
    return Account::isSuperAdmin(m_user);
}
